package com.kaifamiao.service.impl;

import com.kaifamiao.dao.IAccountDao;
import com.kaifamiao.model.Account;
import com.kaifamiao.service.IAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author lucien-ma
 * @date 2021/8/24
 * @apiNote
 */
@Service("accountService")
@Scope("prototype")      // bean 的作用范围设置为多例的
public class IAccountServiceImpl implements IAccountService {

    //@Autowired
    //@Qualifier("testDaoImpl")
    //@Resource(type = IAccountDao.class, name = "testDaoImpl")
    //private IAccountDao accountDao;


    private IAccountDao accountDao;

    @Autowired
    public IAccountServiceImpl(IAccountDao accountDao) {
        this.accountDao = accountDao;
    }


    /**
     * 可以在构造方法上使用，也可以在构造方法的参数里面使用
     * 在参数里面可以单独使用@Qualifier
     */
    //public IAccountServiceImpl(@Qualifier("IAccountDaoImpl") IAccountDao accountDao) {
    //    this.accountDao = accountDao;
    //}

    /**
     * 可以在setter方法上使用
     * @return
     */
    //@Autowired
    //public void setAccountDao(IAccountDao accountDao) {
    //    this.accountDao = accountDao;
    //}

    @PostConstruct
    public void init() {
        System.out.println("IAccountServiceImpl::init...");
    }

    @PreDestroy
    public void destory() {
        System.out.println("IAccountServiceImpl::destory...");
    }

    @Override
    public List<Account> findAll() {
        return accountDao.findAll();
    }
}
